import createElement from "./createElement";
import updataChildren from './updataChildren'

export default function patchVnode(oldVnode, newVnode) {
    if (newVnode.children == undefined) {
        (newVnode.text !== oldVnode.text) ? (oldVnode.elm.innerText = newVnode.text) : undefined
    } else {
        if (oldVnode.children !== undefined && oldVnode.children.length > 0) {
            updataChildren(oldVnode.elm, oldVnode.children, newVnode.children)

        } else {
            oldVnode.elm.innerHTML = ''
            for (let child of newVnode.children) {
                let childDom = createElement(child);
                oldVnode.elm.appendChild(childDom);
            }
        }
    }
}